import dic_tree from "./dic_tree_default_data";
import util from "../libs/util";

const app = {
    state: {
        has_new_message: [],
        dicTree: dic_tree,
        routers: [],
        alive_routers: []
    },
    mutations: {
        setHasNewMessage (state, list) {
            state.has_new_message = list;
        },
        setDicTree (state, dic_tree) {
            state.dicTree = dic_tree;
        },
        updateRouterTree(state, routers) {
            state.routers = routers;
            state.alive_routers = getAliveRoute(routers, []);
        },
    }
};

export default app;

function getAliveRoute(all, arr) {
    all.forEach(item => {
        if(item.meta && item.meta.keepAlive) arr.push(item.name);
        if(item.children && item.children.length) {
            getAliveRoute(item.children, arr);
        }
    });
    return arr;
}
